package com.ruoyi.lh.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.lh.domain.Project;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.lh.mapper.MachineMapper;
import com.ruoyi.lh.domain.Machine;
import com.ruoyi.lh.service.IMachineService;
import com.ruoyi.common.core.text.Convert;

/**
 * 设备Service业务层处理
 *
 * @author LH
 * @date 2023-08-01
 */
@Service
public class MachineServiceImpl implements IMachineService {
  @Autowired private MachineMapper machineMapper;

  /**
   * 查询设备
   *
   * @param id 设备主键
   * @return 设备
   */
  @Override
  public Machine selectMachineById(Long id) {
    return machineMapper.selectMachineById(id);
  }

  /**
   * 查询设备列表
   *
   * @param machine 设备
   * @return 设备
   */
  @Override
  public List<Machine> selectMachineList(Machine machine) {
    return machineMapper.selectMachineList(machine);
  }

  /**
   * 新增设备
   *
   * @param machine 设备
   * @return 结果
   */
  @Override
  public int insertMachine(Machine machine) {
    machine.setCreateTime(DateUtils.getNowDate());
    return machineMapper.insertMachine(machine);
  }

  /**
   * 修改设备
   *
   * @param machine 设备
   * @return 结果
   */
  @Override
  public int updateMachine(Machine machine) {
    machine.setUpdateTime(DateUtils.getNowDate());
    return machineMapper.updateMachine(machine);
  }

  /**
   * 批量删除设备
   *
   * @param ids 需要删除的设备主键
   * @return 结果
   */
  @Override
  public int deleteMachineByIds(String ids) {
    return machineMapper.deleteMachineByIds(Convert.toStrArray(ids));
  }

  /**
   * 删除设备信息
   *
   * @param id 设备主键
   * @return 结果
   */
  @Override
  public int deleteMachineById(Long id) {
    return machineMapper.deleteMachineById(id);
  }

  @Override
  public List<Project> findProjectList() {
    return machineMapper.findProjectList();
  }

  @Override
  public String importMachine(List<Machine> machineList, boolean updateSupport, String loginName) {
    for (Machine machine : machineList) {
      machine.setCreateBy(loginName);
      machine.setUpdateBy(loginName);
      machineMapper.insertMachine(machine);
    }
    return "保存成功";
  }
}
